﻿using Appliaction.Dto.DB;
using Appliaction.IAppServices.DB;
using AutoMapper;
using Domain.Entitys.DB;
using Domain.IRepositorys.DB;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Appliaction.AppServices.DB
{
    public class Db_Product_TypeService : IDb_Product_TypeService
    {
        private readonly IDb_Product_TypeRepository product_TypeRepository;
        private readonly IMapper mapper;

        public Db_Product_TypeService(IDb_Product_TypeRepository product_TypeRepository,IMapper mapper)
        {
            this.product_TypeRepository = product_TypeRepository;
            this.mapper = mapper;
        }

        /// <summary>
        /// 检查同一分类下序号是不是唯一
        /// </summary>
        /// <param name="sort"></param>
        /// <param name="parentId"></param>
        /// <returns></returns>
        public bool CheckSortUnique(int sort, int parentId, int proTypeId)
        {
            return product_TypeRepository.CheckSortUnique(sort, parentId,proTypeId);
        }

        /// <summary>
        /// 条件分页查询产品信息
        /// </summary>
        /// <param name="currentPage"></param>
        /// <param name="pageSize"></param>
        /// <param name="typeName"></param>
        /// <param name="status"></param>
        /// <returns></returns>
        public List<Product_Type_Tree> GetProduct_Types(int currentPage, int pageSize, string typeName, char status)
        {
            return product_TypeRepository.GetProduct_Types(currentPage,pageSize,typeName,status);
        }

        /// <summary>
        /// 添加产品分类信息
        /// </summary>
        /// <param name="product_TypeAddDto"></param>
        /// <returns></returns>
        public async Task<int> Product_TypeAddAsync(Db_Product_TypeAddDto product_TypeAddDto)
        {
            Db_Product_Type db_Product_Type = mapper.Map<Db_Product_Type>(product_TypeAddDto);
            return await product_TypeRepository.Product_TypeAddAsync(db_Product_Type);
        }

        /// <summary>
        /// 条件查询产品总数
        /// </summary>
        /// <param name="typeName"></param>
        /// <param name="status"></param>
        /// <returns></returns>
        public int Product_TypeCount(string typeName, char status)
        {
            return product_TypeRepository.Product_TypeCount(typeName, status);
        }

        /// <summary>
        /// 逻辑删除产品分类信息
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public Task<int> Product_TypeDeleteAsync(List<Db_Product_TypeDelDto> product_TypeDelDto)
        {
            List<Db_Product_Type> db_Product_Type = mapper.Map<List<Db_Product_Type>>(product_TypeDelDto);
            return product_TypeRepository.Product_TypeDeleteAsync(db_Product_Type);
        }

        /// <summary>
        /// 修改产品分类信息
        /// </summary>
        /// <param name="db_Product_Type"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        public Task<int> Product_TypeUpdateAsync(Db_Product_TypeUpdateDto product_TypeUpdateDto)
        {
            Db_Product_Type db_Product_Type = mapper.Map<Db_Product_Type>(product_TypeUpdateDto);
            return product_TypeRepository.Product_TypeUpdateAsync(db_Product_Type);
        }
    }
}
